package wine.logic.interfaces;

import java.util.HashMap;
import java.util.Map;

import javax.ejb.Remote;
import javax.ejb.Stateless;

import wine.ejb.utilities.BaseSessionBean;
import wine.ejb.utilities.PageInfo;
import wine.ejb.utilities.PagedResults;
import wine.ejb.utilities.Utility;
import wine.logic.bean.WModuleDao;
import wine.logic.entity.WModule;
@Stateless
@Remote(WModuleDao.class)
public class WModuleImpl extends BaseSessionBean<WModule> implements WModuleDao {

	@Override
	public PagedResults<WModule> findModuleLst(PageInfo pageInfo) {
		String sql = "from WModule where 1=1 order by iorder desc";
		return super.findListByEJBQL(sql, pageInfo, null);
	}
	
	public Integer validModuleName(WModule module){
		Map<Object, Object> params = new HashMap<Object, Object>();
		StringBuffer ejbql = new StringBuffer("select count(imoduleid) from WModule where smodulename=:moduleName ");
		params.put("moduleName", module.getSmodulename());
		if(Utility.isNotEmpty(module.getImoduleid())){
			ejbql.append("and imoduleid <> :imoduleid ");
			params.put("imoduleid", module.getImoduleid());
		}
		Object o = super.findSingleRecord(ejbql.toString(), params);
		return o == null?0: Integer.parseInt(o.toString());
	}
	public int deleteByImoduleId(Long imoduleid){
		Map<String, Object> params = new HashMap<String, Object>();
		StringBuffer ejbql = new StringBuffer("delete from WModule where imoduleid=:imoduleid");
		params.put("imoduleid", imoduleid);
		return super.executeEJBQL(ejbql.toString(), params);
	}
}
